using System;
using System.Collections.Generic;
using System.Text;

using NSpring.Logging;
using System.IO;
namespace DataProvider
{
    public static class DataLayerLog
    {
        private readonly static Logger logger = null;
        private static String logFile = "C:/logFile.log";

        static DataLayerLog()
        {
            if (File.Exists(Config.LogFile))
            {
                logFile = Config.LogFile;
            }
            else
            {
                try
                {
                    File.Create(Config.LogFile);
                    logFile = Config.LogFile;
                }
                catch
                {
                }
            }
            try
            {
                logger = Logger.CreateFileLogger(logFile);
                logger.IsBufferingEnabled = true;

                logger.BufferSize = 2048;
                logger.Open();
            }
            catch
            {
            }
        }
        private const String spliteLine = "----------------------------------------------------------------------------------------------\r\n";
        public static void LogError(String msg)
        {
            try
            {
                logger.Log(Level.Exception, msg + Environment.NewLine + spliteLine);
            }
            catch
            {
            }
        }
        public static void LogInfo(String msg)
        {
            try
            {
                logger.Log(Level.Verbose, msg + Environment.NewLine + spliteLine);
            }
            catch
            {
            }

        }
        public static void LogException(Exception e)
        {
            try
            {
                logger.Log(e.StackTrace + Environment.NewLine + spliteLine);
            }
            catch
            {
            }
        }
        public static void Close()
        {
            try
            {
                logger.Close();
            }
            catch
            {
            }
        }

    }
}
